package io.renren.modules.wx.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.wx.dao.ChapterDao;
import io.renren.modules.wx.entity.ChapterEntity;
import io.renren.modules.wx.service.ChapterService;


@Service("chapterService")
public class ChapterServiceImpl extends ServiceImpl<ChapterDao, ChapterEntity> implements ChapterService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String key = (String)params.get("key");
        IPage<ChapterEntity> page = this.page(
                new Query<ChapterEntity>().getPage(params),
                StringUtils.isBlank(key) ? new QueryWrapper<>() : new QueryWrapper<ChapterEntity>().eq("course_id", key)
        );

        return new PageUtils(page);
    }

    @Override
    public List<ChapterEntity> getChapterByCourseId(Integer courseId) {

        return baseMapper.selectList(new QueryWrapper<ChapterEntity>().eq("course_id",courseId));

    }

}
